package cn.easybuy.servlet.news;

import cn.easybuy.entity.News;
import cn.easybuy.entity.User;
import cn.easybuy.service.NewsService;
import cn.easybuy.service.impl.NewsServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/newsDetailServlet")
public class NewsDetailServlet extends HttpServlet {
    private NewsService newsService = new NewsServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            int id = Integer.parseInt(req.getParameter("id"));
            News newsById = newsService.getNewsById(id);
            req.setAttribute("news",newsById);
            RequestDispatcher dispatcher = req.getRequestDispatcher("backend/news/newsDetail.jsp");
            dispatcher.forward(req, resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
